package cn.com.lyj6851.modules.edu.service.impl;

import cn.com.lyj6851.common.service.impl.BaseServiceImpl;
import cn.com.lyj6851.dozer.service.IGenerator;
import cn.com.lyj6851.modules.edu.domain.EduComment;
import cn.com.lyj6851.modules.edu.service.EduCommentService;
import cn.com.lyj6851.modules.edu.service.mapper.EduCommentMapper;
import cn.com.lyj6851.modules.edu.vo.CommentVo;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


/**
 * @author Administrator
 */
@Service
@AllArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class EduCommentServiceImpl extends BaseServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {
    private final IGenerator generator;

    @Override
    public CommentVo getCommentListByCourseId(String courseId, int page, int limit) {
        Page<EduComment> pageModel = new Page<>(page, limit);
        Page<EduComment> pageList = baseMapper.selectPage(pageModel,Wrappers.<EduComment>lambdaQuery()
        .eq(EduComment::getCourseId,courseId));
        CommentVo cv = new CommentVo();

        cv.setCommentList(pageList.getRecords());
        cv.setCommentNum(pageList.getTotal());
        return cv;
    }
}
